package cn.bone.vertx.demo01;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.net.NetSocket;

/**
 * Created by MD-01 on 2017/2/9.
 */
public class Client extends AbstractVerticle{

    public static void main(String[] args){
        Runner.run(Client.class);
    }

    @Override
    public void start() throws Exception {
        vertx.createNetClient().connect(1000,"localhost",res -> {
            if(res.succeeded()){
                NetSocket socket = res.result();
                socket.handler(buffer -> {
                    System.out.println("Net client receiving: " + buffer.toString("UTF-8"));
                });

                for(int i=0;i<100;i++){
                    String str = "hello " + i + "\n";
                    System.out.println("Net client sending: " + str);
                    socket.write(str);
                }
            }else{
                System.out.println("Failed to connect " + res.cause());
            }
        });
    }
}
